package com.mdinfo.base.config;

import com.mdinfo.base.config.bean.RedisBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/12/5.
 */
@Configuration
public class RedisConfig {

    @Resource
    private RedisBean redisBean;

    @Bean
    public JedisPool jedisPool(){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setTestOnBorrow(true);
        config.setMaxWaitMillis(redisBean.getMaxWait());
        config.setMaxIdle(redisBean.getMaxIdle());
        config.setMinIdle(redisBean.getMinIdle());
        config.setMaxTotal(redisBean.getMaxTotal());

        JedisPool pool = new JedisPool(config,
                redisBean.getHost(),
                redisBean.getPort(),
                redisBean.getTimeout(),
                redisBean.getPassword(),
                redisBean.getDatabase());
        return pool;
    }
}
